package ThreadBasic.other;

import java.util.concurrent.CountDownLatch;

/**
 * @author yyh
 * @create 2020-11-10 8:31
 *              计数器
 */
public class CountDownLatchDemo {

    public static void main(String[] args) throws InterruptedException {
        // 总数是6，必须要执行任务的时候，再使用！
        CountDownLatch count  = new CountDownLatch(6);

        for (int i = 1; i <= 6; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + "go out");

                // 数量-1
                count.countDown();
            },String.valueOf(i)).start();
        }

        // 等待计数器归零，然后再向下执行
        count.await();

        System.out.println("end......");
    }
}
